from django.contrib import admin
from demo_class.models import BookInfo, HeroInfo


# Register your models here.

# class BookInfoStacked(admin.StackedInline):  块控制
#     model=HeroInfo
#     extra =2


class BookInfoabular(admin.TabularInline):  # 表格形式
    model = HeroInfo
    extra = 2


class BookInfoAdmin(admin.ModelAdmin):
    list_per_page = 2  # 控制列表展示数量

    list_display = ['id', 'bread', 'btitle', 'date']  # 控制展示字段

    search_fields = ['btitle']  # 指定搜索

    actions_on_bottom = True  # 控制执行按钮
    actions_on_top = False

    list_filter = ['bread']  # 过滤
    # 详情页控制
    # fields = ['btitle']

    # 分组展示
    fieldsets = (
        ('基本', {'fields': ['btitle', 'bread','image']}),
        ('高级', {'fields': ['bcomment']})
    )

    inlines = [BookInfoabular]


class HeroInfoAdmin(admin.ModelAdmin):
    list_display = ['id', 'book']


admin.site.register(BookInfo, BookInfoAdmin)
admin.site.register(HeroInfo, HeroInfoAdmin)

admin.site.index_title = '图书管理'
admin.site.site_header = '书城'
admin.site.site_title = '图书管理员'
